package com.itheima.controller;

import com.itheima.pojo.Result;
import com.itheima.utils.AliyunOSSOperator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author hu
 * @date 2025/3/1
 */
@RestController
@Slf4j
public class FileController {
    @Autowired
    private AliyunOSSOperator aliyunOSSOperator;

   /* @PostMapping("/upload")
    public Result fileLoad(String username, Integer age, MultipartFile file) throws IOException {
        log.info("接收到的 请求参数{}，{}，{}", username, age, file);
        String originalFilename = file.getOriginalFilename();
        String s = UUID.randomUUID().toString();
        log.info("{}", s);
        log.info("{}", originalFilename);
        String temp = originalFilename.substring(originalFilename.lastIndexOf("."));
        String newFile = s + temp;
        file.transferTo(new File("D:/temp/" + newFile));
        return Result.success();
    }*/


    @PostMapping("/upload")
    public Result fileLoad(MultipartFile file) throws Exception {
        log.info("接收到的 请求参数->{}", file.getOriginalFilename());
        String url = aliyunOSSOperator.upload(file.getBytes(), file.getOriginalFilename());
        log.info("url:{}",url);
        return Result.success(url);
    }
}
